package com.pig4cloud.pigx.user.controller;

import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.security.annotation.Inner;
import com.pig4cloud.pigx.user.entity.User;
import com.pig4cloud.pigx.user.service.EmailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 邮箱邮件发送
 *
 * @date:2022/8/8
 */
@RestController//接受请求
@RequiredArgsConstructor
@RequestMapping("/email") //访问路径
@Api(value = "user", tags = "平台用户管理")
public class EmailController {

    /**
     * 注入对象
     */
    @Autowired
    private EmailService emailService;


    /**
     * 发送邮箱验证码
     *
     * @param user    邮箱
     * @param message 标识信息
     * @return R
     */
    @Inner(value = false)    // 如果配置在controller类上 是整个类的接口对外暴露
    @ApiOperation(value = "发送邮箱验证码", notes = "发送邮箱验证码，@RequestBody：email，@RequestParam：message")
    @PostMapping("/sendEmail")
    public R sendEmail(@RequestBody User user, @RequestParam String message) {
        user.setLanguageCode(LocaleContextHolder.getLocale().toString());
        return emailService.sendEmail(user, message);
    }


}
